<?php


include '_library/XDb/XDb.class.php';
new XDb('localhost', 'root', '', 'nice');

include '_library/XDao/Model.class.php';
include '_library/XDao/Finder.class.php';
include '_library/XDao/Item.class.php';
include '_library/XDao/List.class.php';


include '_application/models/AuthorDao.class.php';
include '_application/models/BookDao.class.php';
include '_application/models/BookVo.class.php';
include '_application/models/HouseDao.class.php';
include '_application/models/StoreDao.class.php';

echo '<pre>';

$book_dao = new BookDao();
$book = $book_dao->find()->join('author')->join(array('author', 'house'))->first();
print_r($book);
echo '<hr>';

$book_dao = new BookDao();
$book = $book_dao->find()->join('author')->join(array('author', 'house'))->all();
print_r($book);
echo '<hr>';

$author_dao = new AuthorDao();
$author = $author_dao->find()->join('house')->to_array();
print_r($author);
echo '<hr>';

$book_dao = new BookDao();
$book = $book_dao->find()->join('author')->all();
print_r($book);
echo '<hr>';

$author_dao = new AuthorDao($db);
$author = $author_dao->fetch(1);
print_r($author->name);

echo '<hr>';
print_r($author->to_array());
echo '<hr>';

$authors = $author_dao->find()->all();
print_r($authors);
echo '<hr>';

$authors = $author_dao->find()->to_array();
print_r($authors);
echo '<hr>';

$authors = $author_dao->find()->first()->to_array();
print_r($authors);
echo '<hr>';

$authors = $author_dao->find()->where('name', 'like', 'C%')->to_array();
print_r($authors);
echo '<hr>';

$authors = $author_dao->find()->where('id', 'between', array(1, 2))->to_array();
print_r($authors);
echo '<hr>';

$authors = $author_dao->find()->where('id', 'between', array(1, 2))->orderby('name', 'asc')->limit(0, 1)->to_array();
print_r($authors);
echo '<hr>';

$authors = $author_dao->find()->where('id', 'between', array(1, 2))->count();
print_r($authors);
echo '<hr>';

$author = $author_dao->fetch(1);
print_r($author->books()); // array
echo '<hr>';

$book_dao = new BookDao();
$book = $book_dao->fetch(2);
print_r($book->author()->name);
echo '<hr>';

// Example of custom VO object usage
$book = $book_dao->fetch(2)->vo;
print_r($book->getFancyName());
echo '<hr>';

$book = $book_dao->fetch(2);
print_r($book->author()->to_array());
echo '<hr>';

$house_dao = new HouseDao();
$house = $house_dao->fetch(1);
print_r($house->author()->to_array());
echo '<hr>';

$author = $author_dao->fetch(2);
var_dump($author->house()); // no house for this author
echo '<hr>';

$store_dao = new StoreDao();
$store = $store_dao->fetch(2);
print_r($store->books());
echo '<hr>';

$book = $book_dao->fetch(2);
print_r($book->stores());
echo '<hr>';

?>